package org.example.mianshi;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2024/10/24 19:29
 * @apiNote
 */

public class baiduMianshi {
    public static void main(String[] args) {
        int[] nums = {1, 1,3, 3, 4, 3,4, 4,5,6};
        int index = deal(nums);
        System.out.println(index);
        System.out.println(JSON.toJSON(nums));
    }

    public static int deal(int[] nums){
        int n = nums.length;
        int count = 1;
        int pre = nums[0];
        int left = 0;
        for(int i = 1; i < n - 1; i++){
            if(nums[i] == pre){
                count++;
                if(count > 2){
                    for(int j = i+1; j < n; j++){
                        if(nums[j] != pre){
                            nums[i] = nums[j];
                            pre = nums[j];
                            count = 1;
                            left = i;
                            break;
                        }
                    }
                }else{
                    left++;
                }
            }
        }
        return left;
    }
    public static void swap(int[] nums,int left,int right){
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }
}
